﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Portal.Logic.Tests.Units;
using Portal.Model;
using Rhino.Mocks;
using FluentAssertions;
using FluentValidation.TestHelper;

namespace Portal.Logic.Validators.Tests.Units
{
	[TestClass]
	public class ContactInfoValidatorTests : BaseTests
	{

		protected override void InitializeTest() { }

		#region Validate
		[TestMethod]
		public void Validate_EmailInfoIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var info = Mocks.Stub<IContactInfo>();
			info.Value = "aaa@aaa.aaa";
			info.Type = ContactInfoType.Email;
			Mocks.ReplayAll();

			var result = validator.Validate(info);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_MobilePhoneInfoIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var info = Mocks.Stub<IContactInfo>();
			info.Value = "999 000 999";
			info.Type = ContactInfoType.Phone;
			Mocks.ReplayAll();

			var result = validator.Validate(info);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_StationaryPhoneInfoIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var info = Mocks.Stub<IContactInfo>();
			info.Value = "+48 22 842 33 33";
			info.Type = ContactInfoType.Phone;
			Mocks.ReplayAll();

			var result = validator.Validate(info);

			result.IsValid.Should().BeTrue();
		}

        [TestMethod]
        public void Validate_ValueHasMoreThan50Chars_ResultIsNotValid()
        {
            var validator = GetValidator();
            var info = Mocks.Stub<IContactInfo>();
            info.Value = "over50chars1234567890123456789012345678901234567890@test.com";
            info.Type = ContactInfoType.Email;
            Mocks.ReplayAll();

            var result = validator.Validate(info);

            result.IsValid.Should().BeFalse();
            result.Errors.Count.Should().Be(1);
        }

		#endregion

		private ContactInfoValidator GetValidator()
		{
			return new ContactInfoValidator();
		}
	}
}
